package com.minsheng.epidemic_rep.controller;

import com.minsheng.epidemic_rep.entity.FeverClinics;
import com.minsheng.epidemic_rep.service.ScheduledService;
import com.minsheng.epidemic_rep.util.GenerateCsv;
import com.minsheng.epidemic_rep.util.ZipUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


/**
 * @Classname HelloController
 * @Description TODO
 * @Date 2020/9/27 9:46
 * @Created by You
 */
@RestController
public class HelloController {

    /**
     * 生成zip压缩文件
     * @return
     */
    @RequestMapping("/schcsv")
    public String hello() {

        ScheduledService ser = new ScheduledService();
        ser.createCsv();
        return "hello world!";
    }

    //清空目录
    @RequestMapping("/delcsv")
    public String delcsv() {

        ScheduledService ser = new ScheduledService();
        ser.delcsv();
        return "delcsv！";
    }

    public static void main(String[] args) {
        //日期格式转换
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        //从数据库获取发热门诊病人数据
        List<FeverClinics> feverClinicsList = new ArrayList<FeverClinics>();

        //获取今天晚上的具体时间
        String todayTime = sdf1.format(new Date()) + " 00:00:00";
        System.out.println("todayTime: "+todayTime);
        Date todayDateTime = null;//结束时间是今天下午5点
        try {
            todayDateTime = sdf2.parse(todayTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //获取8天前时间参数
        Calendar cal = Calendar.getInstance();
        cal.setTime(todayDateTime);
        cal.add(Calendar.DATE,-7);
        Date startDateTime = cal.getTime();//起始时间是七天前下午5点
        String startTime = sdf2.format(startDateTime);
        System.out.println("startTime: " + startTime);

        //获取1天前时间参数
        cal.setTime(todayDateTime);
        cal.add(Calendar.DATE,-0);
        Date endDateTime = cal.getTime();//起始时间是七天前下午5点
        String endTime = sdf2.format(endDateTime);
        System.out.println("endTime: " + endTime);




    }

}
